/*
 * Cria uma novo form CadastrarAlunoIG
 */
package amanda_gabriel_isabella_lucivania_monica.View;

import amanda_gabriel_isabella_lucivania_monica.Model.Dao.DaoBaseImpl;
import amanda_gabriel_isabella_lucivania_monica.Model.Pojo.Aluno;

/**
 * Interface gráfica de cadastrar aluno
 *
 * @author amanda
 */
public class CadastrarAlunoIG extends javax.swing.JFrame {

    /**
     * Construtor
     *
     * @param DaoBase
     * @param LoginAdministradorIG
     */
    private DaoBaseImpl daoBaseImpl;
    private LoginAdministradorIG loginAdministradorIG;

    public CadastrarAlunoIG(DaoBaseImpl daoBaseImpl, LoginAdministradorIG loginAdministradorIG) {
        initComponents();
        this.setLocation(360, 240);
        this.loginAdministradorIG = loginAdministradorIG;
        this.daoBaseImpl = daoBaseImpl;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDSucesso = new javax.swing.JDialog();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jBSim = new javax.swing.JButton();
        jBNao = new javax.swing.JButton();
        jDCampoVazio = new javax.swing.JDialog();
        jLMsgCampoVazio = new javax.swing.JLabel();
        jBOk = new javax.swing.JButton();
        ConsultarFaltas = new javax.swing.JPanel();
        jLNome = new javax.swing.JLabel();
        jLCpf = new javax.swing.JLabel();
        jTNome = new javax.swing.JTextField();
        jTCpf = new javax.swing.JTextField();
        jBVoltar = new javax.swing.JButton();
        jBCadastrar = new javax.swing.JButton();

        jDSucesso.setTitle("Informação");
        jDSucesso.setMinimumSize(new java.awt.Dimension(400, 175));

        jLabel6.setText("Aluno cadastrado com sucesso!");

        jLabel7.setText("Deseja realizar outro cadastro?");

        jBSim.setText("Sim");
        jBSim.setMinimumSize(new java.awt.Dimension(400, 175));
        jBSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSimActionPerformed(evt);
            }
        });

        jBNao.setText("Não");
        jBNao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBNaoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDSucessoLayout = new javax.swing.GroupLayout(jDSucesso.getContentPane());
        jDSucesso.getContentPane().setLayout(jDSucessoLayout);
        jDSucessoLayout.setHorizontalGroup(
            jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessoLayout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7)
                    .addGroup(jDSucessoLayout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addComponent(jBSim, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jBNao, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(74, Short.MAX_VALUE))
        );

        jDSucessoLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBNao, jBSim});

        jDSucessoLayout.setVerticalGroup(
            jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDSucessoLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addGroup(jDSucessoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBSim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBNao))
                .addContainerGap(48, Short.MAX_VALUE))
        );

        jDSucessoLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jBNao, jBSim});

        jDCampoVazio.setTitle("ATENÇÃO");
        jDCampoVazio.setLocationByPlatform(true);
        jDCampoVazio.setMinimumSize(new java.awt.Dimension(400, 175));

        jLMsgCampoVazio.setText("Todos os campos devem ser preenchidos!");
        jLMsgCampoVazio.setMinimumSize(new java.awt.Dimension(400, 175));

        jBOk.setText("OK");
        jBOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBOkActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jDCampoVazioLayout = new javax.swing.GroupLayout(jDCampoVazio.getContentPane());
        jDCampoVazio.getContentPane().setLayout(jDCampoVazioLayout);
        jDCampoVazioLayout.setHorizontalGroup(
            jDCampoVazioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDCampoVazioLayout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(jDCampoVazioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLMsgCampoVazio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBOk, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(29, Short.MAX_VALUE))
        );
        jDCampoVazioLayout.setVerticalGroup(
            jDCampoVazioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDCampoVazioLayout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLMsgCampoVazio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(28, 28, 28)
                .addComponent(jBOk)
                .addContainerGap(33, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Aluno");
        setMinimumSize(new java.awt.Dimension(400, 175));

        ConsultarFaltas.setBorder(javax.swing.BorderFactory.createTitledBorder("Por favor, insira os dados abaixo:"));

        jLNome.setText("Nome:");

        jLCpf.setText("CPF:");

        javax.swing.GroupLayout ConsultarFaltasLayout = new javax.swing.GroupLayout(ConsultarFaltas);
        ConsultarFaltas.setLayout(ConsultarFaltasLayout);
        ConsultarFaltasLayout.setHorizontalGroup(
            ConsultarFaltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ConsultarFaltasLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ConsultarFaltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLNome)
                    .addComponent(jLCpf))
                .addGap(28, 28, 28)
                .addGroup(ConsultarFaltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTNome, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                    .addComponent(jTCpf))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        ConsultarFaltasLayout.setVerticalGroup(
            ConsultarFaltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ConsultarFaltasLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(ConsultarFaltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLNome)
                    .addComponent(jTNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(ConsultarFaltasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLCpf))
                .addGap(107, 107, 107))
        );

        jBVoltar.setText("Cancelar");
        jBVoltar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBVoltarActionPerformed(evt);
            }
        });

        jBCadastrar.setText("Cadastrar");
        jBCadastrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCadastrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(243, Short.MAX_VALUE)
                        .addComponent(jBCadastrar)
                        .addGap(18, 18, 18)
                        .addComponent(jBVoltar, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(ConsultarFaltas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBCadastrar, jBVoltar});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(ConsultarFaltas, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBVoltar)
                    .addComponent(jBCadastrar))
                .addGap(0, 20, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jBCadastrar, jBVoltar});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jBVoltarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBVoltarActionPerformed
        setVisible(false);
        loginAdministradorIG.setVisible(true);
    }//GEN-LAST:event_jBVoltarActionPerformed

    private void jBCadastrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCadastrarActionPerformed
        String nome = jTNome.getText();
        String cpf = jTCpf.getText();

        if (nome.equals("") || cpf.equals("")) {
            setVisible(false);
            jDCampoVazio.setLocation(360, 240);
            jDCampoVazio.setVisible(true);
        } else {
            Aluno aluno = new Aluno(nome, cpf);
            daoBaseImpl.create(aluno);
            jTNome.setText("");
            jTCpf.setText("");
            setVisible(false);
            jDSucesso.setVisible(true);
            jDSucesso.setLocation(360, 240);
        }
    }//GEN-LAST:event_jBCadastrarActionPerformed

    private void jBSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSimActionPerformed
        setVisible(true);
        jDSucesso.dispose();

    }//GEN-LAST:event_jBSimActionPerformed

    private void jBNaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBNaoActionPerformed
        setVisible(false);
        jDSucesso.dispose();
    }//GEN-LAST:event_jBNaoActionPerformed

    private void jBOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBOkActionPerformed
        setVisible(true);
        jDCampoVazio.dispose();

    }//GEN-LAST:event_jBOkActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ConsultarFaltas;
    private javax.swing.JButton jBCadastrar;
    private javax.swing.JButton jBNao;
    private javax.swing.JButton jBOk;
    private javax.swing.JButton jBSim;
    private javax.swing.JButton jBVoltar;
    private javax.swing.JDialog jDCampoVazio;
    private javax.swing.JDialog jDSucesso;
    private javax.swing.JLabel jLCpf;
    private javax.swing.JLabel jLMsgCampoVazio;
    private javax.swing.JLabel jLNome;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JTextField jTCpf;
    private javax.swing.JTextField jTNome;
    // End of variables declaration//GEN-END:variables
}
